package com.citywithincity.utils;

import java.io.IOException;
import java.io.InputStream;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * 配置加载读取
 * @author Randy
 *
 */
public abstract class ConfigReader {
	
	private static final ConfigReader READER = new ExpandReader();
	
	static{
		try {
			READER.load(null);
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
	protected static final Log logger = LogFactory.getLog(ConfigReader.class);
	
	
	protected ConfigReader() {

	}
	
	public static ConfigReader getDefault(){
		return READER;
	}
	
	public static ConfigReader getReader(String name) throws IOException{
		ConfigReader reader = new PropertyReader();
		reader.load(name);
		return reader;
	}
	
	public static ConfigReader getReader(InputStream inputStream) throws IOException{
		PropertyReader reader = new PropertyReader();
		reader.load(inputStream);
		return reader;
	}
	
	public abstract void load(String name) throws IOException;
	public abstract String get(String key);
	public abstract int getInt(String key);
	
	public abstract String get(String key, String defaultValue);
	
	public int get(String key,int defaultValue){
		 return Integer.parseInt(get(key, String.valueOf(defaultValue)));
	}

	public boolean getBoolean(String string) {
		
		return Boolean.valueOf(get(string, "false"));
	}
}
